from PySide6.QtWidgets import QDockWidget
from PySide6.QtCore import Qt

class CustomDockWidget(QDockWidget):
    def __init__(self, title, parent=None):
        super().__init__(title, parent)
        self.setAllowedAreas(Qt.LeftDockWidgetArea | Qt.RightDockWidgetArea | Qt.BottomDockWidgetArea)
        
        # 添加边框样式
        self.setStyleSheet("""
            QDockWidget {
                border: 1px solid #cccccc;
                border-radius: 3px;
            }
            QDockWidget::title {
                background-color: #f0f0f0;
                padding: 3px;
                border-bottom: 1px solid #cccccc;
            }
        """)
        
    def setWidget(self, widget):
        super().setWidget(widget)
        # 设置默认停靠位置为左侧
        self.setDockArea(Qt.LeftDockWidgetArea)
        
    def setDockArea(self, area):
        """设置停靠区域"""
        if area in [Qt.LeftDockWidgetArea, Qt.RightDockWidgetArea, Qt.BottomDockWidgetArea]:
            self.setAllowedAreas(area)
            if self.parent():
                self.parent().addDockWidget(area, self) 